<#include "${ftl_skin}/common/header.ftl">

</head>
<body class="gray-bg">

<div class="wrapper-content p-b-none animated fadeInRight">
<div class="ibox float-e-margins">
        <!--<div class="ibox-title">用户管理</div>-->
        <div class="ibox-title">
            <div class="row">
                <div class="col-xs-3 ibox-manage">
                    <div id="treeDiv" class='ztree'></div>
                </div>
                <div class="col-sm-9" id="rightDiv">
            <iframe src="${path.viewPath}/index/blank.do" frameborder="0" name="treesetiframe" id="treesetiframe" scrolling="auto"> </iframe>
        </div>
            </div>


        </div>
    </div>

</div>





<#include "${ftl_skin}/common/js.ftl">



<script type="text/javascript" src="${path.commonPath }tools/yxTree/yx.yxTree.js"></script>


<link rel="stylesheet" href="${path.commonPath }tools/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="${path.commonPath }tools/zTree_v3/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="${path.commonPath }tools/zTree_v3/js/jquery.ztree.exedit-3.5.js"></script>


<script type="text/javascript">
    var tree = new yxTree('tree');
    $(function(){
        initTree();
        initIframe();
        winSizeEvent(loadWinSize);
    });

    var firstNode = "";

    function initTree() {
        $.ajax({
            url: "${path.servicePath}/dept/treelistauth.do",
            async: false,
            type: 'POST',
            data: {parent_tree_code:'${parentSeqCode}'},
            complete:function(XMLHttpRequest, textStatus){
            },
            success: function(data){
                if(data.state == 0){
                    var msg = data.result;
                    for(var i in msg){
                        if(i == 0){
                            firstNode = msg[i].tree_code;
                        }
                        tree.nodes[msg[i].parent_tree_code + '_' + msg[i].tree_code] = 'text:' + msg[i].node_name + ';url:' + msg[i].url + ';tree_id:' +  msg[i].id + ';';
                    }
                    var treeNodes = tree.toArr();
                    var json = [];
                    treeToJson(json, treeNodes[0].childNodes);
                    initZTree(json);
                }
            }
        });
    }

    //初始化iframe
    function initIframe(){
        if(firstNode != ""){
            var treeObj = $.fn.zTree.getZTreeObj("treeDiv");
            var node = treeObj.getNodeByParam('id', firstNode);
            treeObj.selectNode(node);
            treeObj.setting.callback.beforeClick(treeObj.setting.treeId, node);
        }
    }

    // 控制页面布局 ( 根据浏览器可视面积动态改变 宽高度 )
    function loadWinSize(){
        // 控制页面布局 ( 根据浏览器可视面积动态改变 宽高度 )
        $('#treesetiframe').height($(window).height() - 70);
        $('#treesetiframe').width($('#rightDiv').width());
    }



    //把数组转换成 json
    function treeToJson(json, treeNodeArr){
        for(var i = 0; i < treeNodeArr.length; i++){
            var tmpJson = {};
//            alert(treeNodeArr[i].attr1);
            tmpJson.id = treeNodeArr[i].sourceId;
            tmpJson.name = treeNodeArr[i].text;
            // tmpJson.url = treeNodeArr[i].url;
            tmpJson.target = 'treesetiframe';
            tmpJson.open = true;
            tmpJson.tree_id = treeNodeArr[i].tree_id;
            if(treeNodeArr[i].hasChild){
                tmpJson.isParent = true;
                tmpJson.children = [];
                treeToJson(tmpJson.children, treeNodeArr[i].childNodes);
            }
            json.push(tmpJson);
        }
    }

    function initZTree(json){

        var setting = {
            view: {
                selectedMulti: false
            },
            edit: {
                enable: false,  //手工打开编辑模式
                editNameSelectAll: false,
                showRemoveBtn: false,
                showRenameBtn: false
            },
            data: {
                simpleData: {
                    enable:true,
                    idKey: "id",
                    pIdKey: "pId",
                    rootPId: ""
                }
            },
            callback: {
                beforeClick: function(treeId, treeNode) {
//                     alert(treeNode.name + ":" + treeNode.id + ":" + treeNode.tree_id);
                    $('#' + treeId).attr('nodeName', treeNode.name).attr('nodeId', treeNode.id);
                   if(treeNode.parentTId) {
                        $('#treesetiframe').attr('src', '${path.viewPath}/user/userlist.do?dept_id=' + treeNode.tree_id);
                    } else {
                        $('#treesetiframe').attr('src', '${path.viewPath}/user/userlist.do?is_load_all=1&dept_id=' + treeNode.tree_id);
                   }
                }
            }
        };

        var zTree = $.fn.zTree.init($("#treeDiv"), setting, json);
    }
	
	$(document).ready(function(){
	 $(".ibox-manage").height($(window).height()- 70);
	});

</script>

<#include "${ftl_skin}/common/footer.ftl">